//
//  Dictionary+ZMExtension.swift
//  TravelForUser
//
//  Created by Rowling on 2020/9/10.
//  Copyright © 2020 智蚂优服. All rights reserved.
//

import Foundation
extension Dictionary : ZMCompatible{}

extension ZM where Base == Dictionary<String, Any> {
    func toJson() -> String? {
        if (!JSONSerialization.isValidJSONObject(base)) {
            print("无法解析出JSONString")
            return nil
        }
        
        guard let data = try? JSONSerialization.data(withJSONObject: base, options: JSONSerialization.WritingOptions.init(rawValue: 0))
        else {return nil}
        let JSONString = String(data: data, encoding: .utf8)
        return JSONString
    }
}

extension ZM where Base == Dictionary<String, String> {
    func toJson() -> String? {
        if (!JSONSerialization.isValidJSONObject(base)) {
            print("无法解析出JSONString")
            return nil
        }
        
        guard let data = try? JSONSerialization.data(withJSONObject: base, options: JSONSerialization.WritingOptions.init(rawValue: 0))
        else {return nil}
        let JSONString = String(data: data, encoding: .utf8)
        return JSONString
    }
}
